import axios from "axios";
import { resReject, resResolve, reqReject, reqResolve } from "./interceptors";

export function createAxios(options = {}) {
  const defaultOptions = {
    timeout: 12000,
  };
  const service = axios.create({
    ...defaultOptions,
    ...options,
  });
  service.interceptors.request.use(reqResolve, reqReject);
  service.interceptors.response.use(resResolve, resReject);
  return service;
}

// export const request = createAxios({
//   baseURL: import.meta.env.VITE_BASE_API,
// })
// console.log(
//   "first",
//   import.meta.env.VITE_APP_BASE_API_TEST,
//   import.meta.env.VITE_BASE_API
// );
// 默认的axios
export const defAxios = createAxios({
  baseURL: import.meta.env.VITE_BASE_API,
});

// 测试的axios
export const testAxios = createAxios({
  baseURL: import.meta.env.VITE_APP_BASE_API_TEST,
});
